package com.lagou.redis;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import javax.sound.midi.Soundbank;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class RedisTest {
    static JedisCluster jedisCluster ;
    @Before
    public void prepare(){
        Set<HostAndPort> set=new HashSet<>();
        set.add(new HostAndPort("192.168.56.101",7001));
        set.add(new HostAndPort("192.168.56.101",7002));
        set.add(new HostAndPort("192.168.56.101",7003));
        set.add(new HostAndPort("192.168.56.101",7004));
        set.add(new HostAndPort("192.168.56.101",7005));
        set.add(new HostAndPort("192.168.56.101",7006));
        set.add(new HostAndPort("192.168.56.101",7007));
        set.add(new HostAndPort("192.168.56.101",7008));
        jedisCluster=new JedisCluster(set);
        System.out.println("jedis starting");
//
//        --cluster create 192.168.56.101:7001 192.168.56.101:7002 192.168.56.101:7003 192.168.56.101:7004 192.168.56.101:7005 192.168.56.101:7006 192.168.56.101:7007 192.168.56.101:7008 --cluster-replicas 1
    }


    @After
    public void close() throws IOException {
        jedisCluster.close();
        System.out.println("close redis");
    }


    @Test
    public void setKey(){
        String hello_redis = jedisCluster.set("name:1", "hello redis");
        System.out.println(hello_redis);
    }
    @Test
    public void  getKey(){
        String s = jedisCluster.get("name:1");
        System.out.println(s);
    }
}
